package com.ytzl.itrip.biz.controller;

import com.alibaba.fastjson.JSON;
import com.ytzl.itrip.beans.model.ItripHotelRoom;
import com.ytzl.itrip.biz.controller.VO.SearchHotelRoomVO;
import com.ytzl.itrip.utils.common.DateUtil;
import com.ytzl.itrip.utils.common.Dto;
import com.ytzl.itrip.utils.common.DtoUtil;
import com.ytzl.itrip.utils.common.EmptyUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by Admin on 2018/4/28.
 */
@Controller
@RequestMapping("/api/hotelroom")
@Api(description = "酒店房型")
public class ItripHotelRoomController {
    @ApiOperation(value = "查询酒店房间列表",
            httpMethod = "GET", response = Dto.class,
            produces = "application/json",
            notes = "根据酒店id查询酒店政策  \\n\" +\n" +
                    "        \"成功：success = ‘true’ | 失败：success = ‘false’ 并返回错误码，如下：  \\n\" +\n" +
                    "        \"10208: 酒店id不能为空  \\n\" +\n" +
                    "        \"10209: 系统异常,获取失败")
    @RequestMapping(value = "/queryhotelroombyhotel",
            method = RequestMethod.GET,
            produces = "application/json")
    @ResponseBody
    public Dto queryhotelroombyhotel(@ResponseBody SearchHotelRoomVO searchHotelRoomVO) {
        if (EmptyUtils.isEmpty(searchHotelRoomVO.getHotelId())){
            return DtoUtil.returnFail("酒店Id不能为空","100303");
        }
        if (EmptyUtils.isEmpty(searchHotelRoomVO.getStartDate())||EmptyUtils.isEmpty(searchHotelRoomVO.getEndDate())){
            return DtoUtil.returnFail("酒店入住以及退房时间不能为空","100303");
        }
        try {
            Date startTime= new SimpleDateFormat("yyyy-MM-dd").parse(searchHotelRoomVO.getStartDate());
            Date endTime= new SimpleDateFormat("yyyy-MM-dd").parse(searchHotelRoomVO.getEndDate());

            if (startTime.getTime()>endTime.getTime()){
                return DtoUtil.returnFail("入住时间不能大于退房时间","100303");
            }
            dateList= DateUtil.getBetweenDates(startTime,endTime);
        }catch (Exception e){
            e.printStackTrace();
        }
        Map<String,Object> param= JSON.parseObject(
                JSON.toJSONString(searchHotelRoomVO),Map.class);
        param.put("dateList",dateList);

        List<ItripHotelRoom> itripHotelRoomList=itripHotelRoomService.getItripHotelRoomListByMap(param);
        return  DateUtil

    }
}
